<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="./css/index.css" />
  <title>计数器</title>
</head>

<body>
  <div class="my-input-number">
    <!-- 递减 -->
    <span @click="sub" role="button" class="my-input-number__decrease" :class="{'is-disabled': num == 0}">
      -
    </span>
    <!-- 累加 -->
    <span @click="add" role="button" class="my-input-number__increase" :class="{'is-disabled': num == 10}">
      +
    </span>
    <div class="my-input">
      <!-- 数字显示区域 -->
      <span class="my-input__inner">{{ num }}</span>
    </div>
  </div>
  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el: '.my-input-number',
      data: {
        num: 0
      },
      methods: {
        // +号的点击事件
        add () {

          // 小于10才允许++
          if (this.num < 10) {
            this.num++
          }
        },
 
        // -号的点击事件
        sub () {
          // 大于0才允许--
          if (this.num > 0 ) {
            this.num--
          }
        }
      }
    })
  </script>
</body>

</html>